package com.yangfan.springcloud.service.impl;

import cn.hutool.core.util.IdUtil;
import com.yangfan.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

@EnableBinding(Source.class) //这里不在写 @Service  这个注解 因为这个类是跟 中间件打交道的类并不是 MVC 的 Service
@Slf4j
public class IMessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //发送管道

    @Override
    public void send() {
        String uuid = IdUtil.randomUUID();
        log.info("我是8002:"+ uuid);
        output.send(MessageBuilder.withPayload("我是8002:"+ uuid).build());
    }


}
